<template>
  <!--表格渲染-->
  <DataGridTable
    v-loading="loading"
    :sup_this="sup_this"
    :data="data"
    :show-page="false"
    :multi-select="false"
    :show-row-number="true"
    row-key="id">
    <el-table-column v-if="checkPermission(['SYS_ADMIN','COMMON_ADMIN','ROLE_ALL','ROLE_DELETE'])" label="操作" width="130px" align="center">
      <template slot-scope="scope">
        <el-popover
          v-permission="['SYS_ADMIN','COMMON_ADMIN','ROLE_ALL','ROLE_DELETE']"
          :ref="scope.row.id"
          placement="top"
          width="180">
          <p>确定要移除吗？</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
            <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
          </div>
          <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column prop="formCode" label="表单编号"/>
    <el-table-column prop="formName" label="名称"/>
    <el-table-column prop="createDate" label="创建日期">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.createDate) }}</span>
      </template>
    </el-table-column>
  </DataGridTable>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { deleteRoleForm, findFormByRoleIdUrl } from '@/api/system/role'
import { parseTime } from '@/utils/index'

export default {
  mixins: [initData],
  props: {
    sup_this: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      delLoading: false,
      roleId: ''
    }
  },
  created() {
    this.pageCount = false
    this.url = findFormByRoleIdUrl()
  },
  methods: {
    parseTime,
    checkPermission,
    loadData() {
      this.init()
    },
    async beforeInit() {
      this.paramBean.id = this.roleId
      return true
    },
    subDelete(id) {
      this.delLoading = true
      const data = { busMainData: { roleFormVOList: [{ id: id }] }}
      deleteRoleForm(data).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.init()
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err)
      })
    }
  }
}
</script>

<style scoped>
</style>
